/**
 * 实现商品添加，修改，查询， 删除
 */
const express = require('express')
const { queryDBPromise } = require('../util/db')
const goodsRouter = express.Router() // 路由对象

/**
 * 商品添加
 *   method:POST
 *   url:/goods
 *   参数: name,price,num,url
 */
goodsRouter.post('/goods',(req,res)=>{
    const name = req.body.name
    const price = req.body.price
    const num = req.body.num
    const url = req.body.url

    const sql = `INSERT INTO goods (name,price,num,url)VALUES('${name}',${price},${num},'${url}')`
    queryDBPromise(sql).then(data=>{
        res.send({
            code:1,
            mesasge:'添加商品成功！'
        })
    }).catch(err=>{
        res.send({
            code:-1,
            message:'添加商品失败!'
        })
    })
})

module.exports = {goodsRouter}